package com.jwdf.uda.utils;

import java.text.DecimalFormat;

/**
 * 类说明：单位换算工具
 * 作者：huangqiuxin on 2016/5/16 17:39
 * 邮箱：648859026@qq.com
 */
public class UnitUtils {
    private static DecimalFormat df = new DecimalFormat("#");

    public static String FormatFileSize(long size) {
        // 转换文件大小
        String fileSizeStr = "";
        if (size == 0) {
        } else if (size < 1024) {
            fileSizeStr = df.format((double)size) + "B";
        } else if (size < 1048576) {
            fileSizeStr = df.format((double)size / 1024) + "K";
        } else if (size < 1073741824) {
            fileSizeStr = df.format((double)size / 1048576) + "M";
        } else {
            fileSizeStr = df.format((double)size / 1073741824) + "G";
        }
        return fileSizeStr;
    }

    private static DecimalFormat pdf1 = new DecimalFormat("0.00");
    public static String formatPrice(double price){
        return pdf1.format(price);
    }

}
